package com.yang.dao.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.List;

/**
 * 商品规格
 * 作者：孤城暖阳y
 * 开发时间：2025-03-15
 */
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("category")
@Data
@Accessors(chain = true)
@Document(collection = "specs")
// 当属性为默认值时，不序列化
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class SpecsDO implements Serializable, Cloneable {

    /**
     * MongoDB中specs表的id
     */
    @Id
    @JsonIgnore
    private long id;

    /**
     * 商品id
     */
    private Long commodityId;

    /**
     * 商品名称和sku参数名称
     */
    private String name;

    /**
     * 商品sku参数值
     */
    private String valueName;

    /**
     * 商品sku参数值
     * 一个商品的sku参数值可能有多个，所以用List存储
     */
    private List<Values> values;

    @Override
    public String toString() {
        return "SpecsDO{" +
                "id=" + id +
                ", commodityId=" + commodityId +
                ", name='" + name + '\'' +
                ", valueName='" + valueName + '\'' +
                ", values='" + values + '\'' +
                '}' + "\n";
    }

    @Override
    public SpecsDO clone() {
        try {
            // TODO: 复制此处的可变状态，这样此克隆就不能更改初始克隆的内部项
            return (SpecsDO) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
